package org.coopac.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import org.coopac.dao.IUbigeoDAO;
import org.coopac.model.CoopacUbigeo;
import org.coopac.service.IUbigeoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service("ubigeoService")
public class UbigeoService implements IUbigeoService {
	
	@Autowired
	private IUbigeoDAO ubigeoDAO;
	
	@Override
	public CoopacUbigeo getById(int id) {
		return ubigeoDAO.getById(id);
	}
	
	@Override
	public List<CoopacUbigeo> listar() {
		return ubigeoDAO.listar();
	}

	@Override
	public List<CoopacUbigeo> listById(int id) {
		return ubigeoDAO.listById(id);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public List<SelectItem> listaUbigeo(int id) {
		List<CoopacUbigeo> o = new ArrayList<CoopacUbigeo>();
		o.addAll(ubigeoDAO.listById(id));
		List list = new ArrayList<SelectItem>();
		for(CoopacUbigeo ob:o){
			list.add(new SelectItem(ob.getIdUbigeo(),ob.getNombreUbigeo()));
		}
		return list;
	}
	
}
